#ifndef __OLED_H
#define __OLED_H

#include "./SYSTEM/SYS/sys.h"
#include "./BSP/OLED/OLED_Data.h"
#include <stdint.h>

/* OLED端口定义 */
#define OLED_SCL_GPIO_PORT               GPIOB                                         /* SCL引脚所在的GPIO端口 */
#define OLED_SCL_GPIO_PIN                GPIO_PIN_8                                    /* SCL引脚的GPIO引脚号 */
#define OLED_SCL_GPIO_CLK_ENABLE()       do{ __HAL_RCC_GPIOB_CLK_ENABLE(); }while(0)   /* SCL引脚所在IO口时钟使能 */

#define OLED_SDA_GPIO_PORT               GPIOB                                         /* SDA引脚所在的GPIO端口 */
#define OLED_SDA_GPIO_PIN                GPIO_PIN_9                                    /* SDA引脚的GPIO引脚号 */
#define OLED_SDA_GPIO_CLK_ENABLE()       do{ __HAL_RCC_GPIOB_CLK_ENABLE(); }while(0)   /* SDA引脚所在IO口时钟使能 */

/* OLED端口控制函数定义 */
/* 利用操作寄存器的方式控制IO引脚提高屏幕的刷新率 */
#define OLED_SCL(x)      OLED_SCL_GPIO_PORT->BSRR = (x) ? OLED_SCL_GPIO_PIN : ((uint32_t)OLED_SCL_GPIO_PIN << 16)   /* 设置SCL引脚 */
#define OLED_SDA(x)      OLED_SDA_GPIO_PORT->BSRR = (x) ? OLED_SDA_GPIO_PIN : ((uint32_t)OLED_SDA_GPIO_PIN << 16)   /* 设置SDA引脚 */

/* FontSize参数取值 */
/* 此参数值不仅用于判断，而且用于计算横向字符偏移，默认值为字体像素宽度 */
#define OLED_8X16               8
#define OLED_6X8                6

/* IsFilled参数数值 */
#define OLED_UNFILLED           0
#define OLED_FILLED             1

/* 初始化函数 */
void OLED_Init(void);

/* 更新函数 */
void OLED_Update(void);
void OLED_UpdateArea(int16_t X, int16_t Y, uint8_t Width, uint8_t Height);

/* 显存控制函数 */
void OLED_Clear(void);
void OLED_ClearArea(int16_t X, int16_t Y, uint8_t Width, uint8_t Height);
void OLED_Reverse(void);
void OLED_ReverseArea(int16_t X, int16_t Y, uint8_t Width, uint8_t Height);

/* 显示函数 */
void OLED_ShowChar(int16_t X, int16_t Y, char Char, uint8_t FontSize);
void OLED_ShowString(int16_t X, int16_t Y, char *String, uint8_t FontSize);
void OLED_ShowNum(int16_t X, int16_t Y, uint32_t Number, uint8_t Length, uint8_t FontSize);
void OLED_ShowSignedNum(int16_t X, int16_t Y, int32_t Number, uint8_t Length, uint8_t FontSize);
void OLED_ShowHexNum(int16_t X, int16_t Y, uint32_t Number, uint8_t Length, uint8_t FontSize);
void OLED_ShowBinNum(int16_t X, int16_t Y, uint32_t Number, uint8_t Length, uint8_t FontSize);
void OLED_ShowFloatNum(int16_t X, int16_t Y, double Number, uint8_t IntLength, uint8_t FraLength, uint8_t FontSize);
void OLED_ShowImage(int16_t X, int16_t Y, uint8_t Width, uint8_t Height, const uint8_t *Image);
void OLED_Printf(int16_t X, int16_t Y, uint8_t FontSize, char *format, ...);

/* 绘图函数 */
void OLED_DrawPoint(int16_t X, int16_t Y);
uint8_t OLED_GetPoint(int16_t X, int16_t Y);
void OLED_DrawLine(int16_t X0, int16_t Y0, int16_t X1, int16_t Y1);
void OLED_DrawRectangle(int16_t X, int16_t Y, uint8_t Width, uint8_t Height, uint8_t IsFilled);
void OLED_DrawTriangle(int16_t X0, int16_t Y0, int16_t X1, int16_t Y1, int16_t X2, int16_t Y2, uint8_t IsFilled);
void OLED_DrawCircle(int16_t X, int16_t Y, uint8_t Radius, uint8_t IsFilled);
void OLED_DrawEllipse(int16_t X, int16_t Y, uint8_t A, uint8_t B, uint8_t IsFilled);
void OLED_DrawArc(int16_t X, int16_t Y, uint8_t Radius, int16_t StartAngle, int16_t EndAngle, uint8_t IsFilled);

/* 测试函数 */
void OLEDTest(void);

#endif
